//
//  QYXDailyTableViewCell.m
//  OpenYourEyes
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 Google AdWords. All rights reserved.
//

#import "QYXDailyTableViewCell.h"
#import "UIImageView+QYXCarveImage.h"
@implementation QYXDailyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.mainImageView = [[UIImageView alloc] init];
        [UIImageView CareImageWithUIImageView:_mainImageView];
        [self.contentView addSubview:_mainImageView];
        
        //初始化view
        self.blackView = [[UIView alloc] init];
        self.blackView.backgroundColor = [UIColor blackColor];
        self.blackView.alpha = 0.2;
        [self.mainImageView addSubview:_blackView];
        
        //初始化titleLabel
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = [UIColor whiteColor];
        self.titleLabel.textAlignment = 1;


        self.titleLabel.font = [UIFont fontWithName:@"FZLTZCHJW--GB1-0" size:17];
        [self.mainImageView addSubview:_titleLabel];
        
        //初始化动画label
        self.activeTimeLabel = [[UILabel alloc] init];
        self.activeTimeLabel.textColor = [UIColor whiteColor];
        self.activeTimeLabel.textAlignment = 1;


        self.activeTimeLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:13];
        [self.mainImageView addSubview:_activeTimeLabel];
        
        //初始化全景label
        self.fullViewLabel = [[UILabel alloc] init];
        self.fullViewLabel.textColor = [UIColor whiteColor];
        self.fullViewLabel.textAlignment = 2;
        self.fullViewLabel.font = [UIFont systemFontOfSize:15];
        [self.mainImageView addSubview:_fullViewLabel];


        
        
        UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
        [self.contentView addGestureRecognizer:longGesture];

    }
    return self;
}
- (void)longTap:(UILongPressGestureRecognizer *)sender
{
    self.titleLabel.textColor = [UIColor colorWithWhite:1.000 alpha:0.000];
    self.activeTimeLabel.textColor = [UIColor colorWithWhite:1.000 alpha:0.000];
    self.fullViewLabel.textColor = [UIColor colorWithWhite:1.000 alpha:0.000];
    self.blackView.backgroundColor = [UIColor clearColor];
    if (sender.state == UIGestureRecognizerStateEnded) {
        self.blackView.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.400];
        self.titleLabel.textColor = [UIColor whiteColor];
        self.activeTimeLabel.textColor = [UIColor whiteColor];
        self.fullViewLabel.textColor = [UIColor whiteColor];
    }
    
}
#pragma mark -- 尺寸大小
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.mainImageView.frame = self.contentView.bounds;
    self.blackView.frame = self.mainImageView.bounds;
    self.titleLabel.frame = CGRectMake(0, self.mainImageView.bounds.size.height / 2 - 25, self.mainImageView.bounds.size.width, 20);
    self.activeTimeLabel.frame = CGRectMake(0, self.titleLabel.frame.size.height + self.titleLabel.frame.origin.y + 10, self.mainImageView.bounds.size.width, 20);
    self.fullViewLabel.frame = CGRectMake(0, 10, self.mainImageView.bounds.size.width - 10, 20);
}

#pragma mark -- model
- (void)setModel:(QYXDailyItemListModel *)model
{
    if (_model != model) {
        _model = model;
        [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:[_model.cover objectForKey:@"feed"]] placeholderImage:kPlaceHolderImage];
        self.titleLabel.text = _model.title;
        self.fullViewLabel.text = [_model.label objectForKey:@"text"];
        self.activeTimeLabel.text = [NSString stringWithFormat:@"#%@  /  %ld'%ld''", _model.category, _model.duration / 60, _model.duration % 60];
    }
    
}




- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
